/****************************************************
    文件：UIMainView.cs
    作者：L.S.Xing
    邮箱: 170105971@qq.com
    日期：#CreateTime#
    功能：
*****************************************************/

using System.Collections.Generic;
using UnityEngine;



namespace LSX
{
    public class UIMainView : MonoBehaviour
    {
        [SerializeField] RectTransform BottomBar;
        [SerializeField] RectTransform MainView;

        [SerializeField] List<UIBottomBarItemSO> UIBottomBarItemList;


        private void Awake()
        {
            // 循环遍历数组
            for (var i = 0; i < UIBottomBarItemList.Count; i++)
            {
                // 生成UIBottomBar Item
                var uIBottomBarItem = Instantiate(UIBottomBarItemList[i].bottomBarItem).GetComponent<UIBottomBarItem>();
                uIBottomBarItem.transform.SetParent(BottomBar);
                uIBottomBarItem.transform.localScale = Vector3.one;

                // 生成要显示的内容的Game Object
                var content = Instantiate(UIBottomBarItemList[i].content);
                content.transform.SetParent(MainView);
                content.transform.localScale = Vector3.one;

                // 设置布局
                var rect = content.GetComponent<RectTransform>();
                rect.offsetMin = Vector2.zero;
                rect.offsetMax = Vector2.zero;

                // 进行初始化操作
                uIBottomBarItem.Init(i, content, UIBottomBarItemList[i].itemName);
            }
        }
    }
}